<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Game\Controller;

use Think\Controller;

class TestController extends Controller {

    function index() {
        echo wx_openid();exit;
        $bool = R('Api/Fans/updateFansByOpenid',array(wx_openid()));
       
        if ($bool === true) {
           echo 111;
            // $redirec_url = 'http://a.forcent.cn/ldh/store.php/Member/requestQrcode/' . $url;
            // redirect('http://a.forcent.cn/iHuiyuan/user/Integral?url=' . ($redirec_url));
        } else {
            redirect('http://mp.weixin.qq.com/s?biz=MjM5ODg1MDI2OA==&mid=209800739&idx=1&sn=54b350a36b6655303eadca02c425ddb9#rd');
        }
    }

    function aa($openid) {
        set_time_limit(0);
        $data = S('opencache' . $openid);
        if (empty($data)) {
            $dbdata = M('openid')->select();
            foreach ($dbdata as $key => $value) {
                $arr[] = $value['openid'];
            }
            $url = "https://api.weixin.qq.com/cgi-bin/user/get?access_token=" . wx_access_token();
            $data = http_get($url);
            $openlist = json_decode($data, true);
            $openidArr = $openlist['data']['openid'];
            //print_r($openidArr);exit;
            $c = array_intersect($openidArr, $arr);
            $b = array_diff($openidArr, $arr);
            $d = array_merge(array_diff($openidArr, $arr));
            // print_r($d);  echo count($openidArr);exit;

            $datalist = array();
            echo '<br>';
            echo count($b);
            print_r($b);
            echo '<br>';
            echo count($c);
            //   print_r($c);
            echo '<br>';
            // print_r($openidArr);
            echo count($openidArr);
            foreach ($b as $key => $value) {
                $datalist[] = array('openid' => $b[$key]);
            }
            //print_r($datalist);
            M('Openid')->addAll($datalist);
            S('opencache' . $openid, $openid, 3600 * 4);
            //exit;
        }
    }

}
